'''
Created on 2009. 6. 21.

@author: natas999
'''


import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


class MainPage(webapp.RequestHandler):
    def get(self):

        template_values = {
            'page_title' :"Testing...",
            'max_players' : range(2, 6),
        }

        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))


class MakeSkel(webapp.RequestHandler):
    def post(self):
        players = int(cgi.escape(self.request.get('players')))
        template_values = {
            'ladder_size' : range(80),
            'players' : range(players - 1),
            'player_names' : range(players),
            'name_full_width' : 122 * players,
        }

        path = os.path.join(os.path.dirname(__file__), 'ladder.html')
        self.response.out.write(template.render(path, template_values))


application = webapp.WSGIApplication([
                                      ('/', MainPage),
                                      ('/make_skel', MakeSkel),
                                     ], debug = True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
